﻿using System.Windows;
using MefBasic.Data;

namespace MefBasic
{
    public abstract class APresenter<T>:DependencyNotifyObject, IPresenter<T> where T:IView
    {
        protected APresenter(T view)
        {
            View = view;
            View.DataContext = this;
        }


        public T View
        {
            get { return (T)GetValue(ViewProperty); }
            set { SetValue(ViewProperty, value); }
        }

        public static readonly DependencyProperty ViewProperty =
            DependencyProperty.Register("View", typeof(T), typeof(APresenter<T>), new UIPropertyMetadata(null));

        protected static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var presenter = (APresenter<T>)d;
            presenter.DoPropertyChanged(e);
        }

        protected virtual void DoPropertyChanged(DependencyPropertyChangedEventArgs e)
        {
            
        }
    }
}